<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml"
      xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>申购管理</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
          name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--插件样式-->
    <link rel="stylesheet" href="/dist/plugins/select2/select2.min.css">
    <!--插件样式-->
    <link href="/dist/plugins/ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet"/>
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=39cd89cd">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=16f1e6f3">
    <style>
        .table > tbody > tr > td {
            line-height: 24px;
            max-height: 24px;
            overflow: hidden;
        }

        span.lineOne {
            line-height: 28px;
            height: 28px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
        }

        .div-td-content-more {
            position: absolute;
            height: auto;
            z-index: 999;
            line-height: 20px;
            background-color: #d3e8fd;
            padding: 8px 6px;
            border: 1px solid #e8e8ea;
            display: none;
        }

        .divCheck {
            height: 100%;
            margin-left: 5px;
            line-height: 25px;
        }

        .divCheck input {
            float: left;
            margin-top: 7px;
            margin-right: 5px;
        }

        .div-td-content-more i {
            width: 15px;
            height: 12px;
            background: url("/dist/img/more-icon.png");
            position: absolute;
            left: 50px;
            top: -12px;
        }

        .left {
            width: 170px;
            float: left;
        }

        .right {
            margin-left: 180px;
        }

        .templateStyle {
            border: 1px solid #ddd;
            padding: 0 10px;
        }

        .lineOne {
            text-align: left;
        }

        .lineOne span {
            max-height: 20px;
            line-height: 20px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            text-align: left;
        }

        .lineOneNoMore {
            text-align: left;
        }

        .lineOneNoMore span {
            max-height: 20px;
            line-height: 20px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 1;
            text-align: left;
        }
        .table{
            border:1px solid #cbcbcd;
        }

        .jiaobiao3 {
            position: relative;
        }

        .jiaobiao3 i {
            display: block;
            width: 6px;
            height: 6px;
            background: url("/dist/img/newLog3.png");
            position: absolute;
            top: 0px;
            right: 5px;
        }
        .divCheck {
            height: 100%;
            margin-left: 5px;
            line-height: 25px;
        }

        .divCheck input {
            float: left;
            margin-top: 7px;
            margin-right: 5px;
        }
    </style>
</head>
<body>
<section class="content" id="app">
    <div class="div-td-content-more"><i></i></div>
    <iframe id="ifExprot" style="width:0px;height:0px;display: none;" frameborder="0"></iframe>
    <div style="height: 25px;margin-bottom: 10px;">
        <input type="text" placeholder="请输入关键字" class="form-control pull-left input-sm"
               style="width: 200px;" v-model="searchParams.key">
        <button type="button" class="btn oaBtn btn-sm"
                style="margin-left: 10px;float: left;" @click="search">查询
        </button>
       <!-- <button type="button" class="btn oaBtn pull-right btn-sm" style="margin-right: 20px"
                @click="inRepoBtn"/>
        入库
        </button>-->
        <button type="button" class="btn oaBtn pull-right btn-sm" style="margin-right: 20px"
                @click="inventoryGoodsBtn"/>
        申购
        </button>
    </div>
    <div class="box-body no-padding iframeH3" id="scrollDiv">
        <table class="table table-hover  text-center table-striped">
            <thead>
            <tr>
                <th style="width: 17px">序号</th>
                <th style="width: 50px">申购日期</th>
                <th style="width: 50px">公司</th>
                <th style="width: 80px">物品名称</th>
                <th style="width: 25px">状态</th>
                <th style="width: 45px">审核状态</th>
                <th style="width: 25px">操作</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="(item,i) in list">
                <td style="margin-right: 6px;">{{i+nowPage+1}}</td>
                <td>{{item.applyDate}}</td>
                <td>{{item.companyName}}</td>
                <td>
                    <span style="color:#2a8cec;cursor: pointer;" @click="goDetail(item,'look','see',i)">
                        {{item.goodsName}}
                    </span>
                </td>
                <td v-html="convertStateToName(item)" style="width:80px;"></td>
                <td v-html="convertAuditFlagToName(item)" style="width:80px;"></td>
                <td>
                    <a href="javascript:void(0);" @click="goDetail(item,'edit','update',i)"
                       v-if="currentUser.id==item.createUserId && (item.auditFlag=='-1' || item.auditFlag=='2')"
                       style="color:#2a8cec;cursor: pointer;text-align: center">编辑
                    </a>
                    <a style="text-align: center;color: #CCCCCC"
                       v-else>编辑
                    </a>
                    <a href="javascript:void(0);" @click="goDetail(item,'look','audit',i)"
                       v-if="currentUser.id==item.currentAuditorId && item.auditFlag=='0'">
                        审核
                    </a>
                    <a style="text-align: center;color: #CCCCCC" v-else>
                        审核
                    </a>
                    <a href="javascript:void(0);" @click="goDetail(item,'edit','buy',i)"
                       v-if="item.state == '0'">
                        采购
                    </a>
                    <a style="text-align: center;color: #CCCCCC" v-else>
                        采购
                    </a>
                    <a href="javascript:void(0);" @click="makeSure(item)"
                       v-if="item.state == '1'">
                        确认到达
                    </a>
                    <a style="text-align: center;color: #CCCCCC" v-else>
                        确认到达
                    </a>
                    <a href="javascript:void(0);" @click="inRepo(item)"
                       v-if="item.state == '2'">
                        入库
                    </a>
                    <a style="text-align: center;color: #CCCCCC" v-else>
                        入库
                    </a>
                </td>
            </tr>
            </tbody>
        </table>

    </div>
    <div class="oa-pager text-center" style="margin-top: 5px;">
        共
        <span id="allCount"> 0 </span>条记录&nbsp;&nbsp;&nbsp;
        <span id="nowPage"> 1 </span>/<span id="allPage">1</span>&nbsp;&nbsp;&nbsp;
        <span class="oa-pager-button" id="first">首页</span>
        <span class="oa-pager-button" id="prev">上一页</span>
        <span class="oa-pager-button" id="next">下一页</span>
        <span class="oa-pager-button" id="last">尾页</span>
    </div>
</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=7e54a132"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=558d0414"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript" src="/dist/plugins/My97DatePicker/WdatePicker.js"></script>
<!--ztree组件所需js-->
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.exhide-3.5.js"></script>
<script>
    $(function () {
        $("body").on("click", ".lineOne", function (e) {
            if ($(".div-td-content-more").is(":hidden")) {
                var text = $(this).text();
                if (text != "") {
                    text = "<i></i>" + text;
                    $(".div-td-content-more").html(text).css({
                        "width": $(this).outerWidth() + "px",
                        "left": $(this).offset().left,
                        "top": ($(this).offset().top + $(this).outerHeight()) + "px"
                    }).show();
                    e.stopPropagation();
                }
            } else {
                $(".div-td-content-more").hide();
            }
        });
        $("body").on("click", ".div-td-content-more", function (e) {
            e.stopPropagation();
        });
        $("body").on("click", function () {
            $(".div-td-content-more").hide();
        });
    });
</script>
<script type="text/javascript">
    var api = frameElement.api;
    function refresh() {
        app.allUserIdList = [];
        $.wyui.page.getByPage();
    }
    var app = new Vue({
        el: '#app',
        data: {
            currentUser: getCurrentUser(),
            pageType: $.wyui.page.urlParams.pageType,
            list: [{
                goodsInfo:[]
            }],
            nowPage: 0,
            searchParams: {
                userId: $.wyui.page.urlParams.userId ? $.wyui.page.urlParams.userId : getCurrentUser().id,
                key: '',
                companyId:$.wyui.page.urlParams.companyId ,
                date: new Date().Format("yyyy-MM-dd")
            },
            selectId: '',
            isCheckNew: false
        },
        methods: {
            //申购
            inventoryGoodsBtn: function () {
                $.dialog({
                    content: 'url:/page/psi/purchase.html?pageType=edit' + '&type=add' + "&t="+ new Date(),
                    title: '申购物品详情',
                    width: 904,
                    height: 535,
                    max: true,
                    min: true,
                    lock: true
                });
            },
            //入库
            inRepoBtn: function (item) {
                var that=this;
                var id = item.id;
                $.dialog({
                    content: 'url:/page/psi/in_repo.html?pageType=edit' +"&purchaseId="+id+"&t="+ new Date(),
                    title: '入库物品详情',
                    width: 904,
                    height: 535,
                    max: true,
                    min: true,
                    lock: true
                });
            },
            //出库
            outRepoBtn: function () {
                $.dialog({
                    content: 'url:/page/psi/out_repo.html?pageType=edit' + "&t="+ new Date(),
                    title: '出库物品详情',
                    width: 904,
                    height: 535,
                    max: true,
                    min: true,
                    lock: true
                });
            },
            //确认到达
            makeSure:function (item) {
                var id = item.id;
                var flag = '1';
                console.log(id)
                if (!confirm("商品确定到达吗？")) {
                    return;
                }
                $.wyui.postMethod(urlConfig.psi.purchase.updateState,
                    {id: id, flag: flag},
                    function (data) {
                        alert("商品到达");
                        $.wyui.page.getByPage();
                    });
            },
            //入库
            inRepo:function (item) {
                var id = item.id;
                var flag = '2';
                var inRepoDate = new Date().Format("yyyy-MM-dd");
                var inUserId = currentUser.id;
                var inUserName = currentUser.name;
                console.log(id)
                if (!confirm("商品确定入库吗？")) {
                    return;
                }
                $.wyui.postMethod(urlConfig.psi.purchase.updateState,
                    {id: id, flag: flag, inRepoDate: inRepoDate, inUserId: inUserId, inUserName: inUserName},
                    function (data) {
                        alert("商品入库");
                        $.wyui.page.getByPage();
                    });
            },
            //删除库存商品
            removeById: function (id, i) {
                if (confirm('确认要删除吗？')) {
                    var that = this;
                    $.wyui.postMethod(urlConfig.psi.goods.removeById, {id: id}, function (result) {
                        that.list.splice(i, 1);
                    });
                }
            },
            //跳转页  编辑和查看
            goDetail: function (item,pageType,type,i) {
                var that = this;
                var id = item.id;
                var purchaseId = item.id;
                console.log(item)
                console.log(item.id)
                //新增 pageType='edit'&type='add'
                //编辑 pageType='edit'&id='xx'&type='update'
                //审核 pageType='edit'&id='xx'&type='shenhe'
                //采购 pageType='edit'&id='xx'&type='caigou'
                //查看 pageType='look'&id='xx'&type='chakan'

                //采购 显示 type='caigou'||采购日期有值
                //       type='caigou'  input
                //       span

                if(item.state == '1'){
                    var condition = '?id=' + id;
                    if (pageType != 'edit') {
                        condition += '&pageType=' + pageType;
                        top.addTabs({
                            id: 'GoodsDetail',
                            title: '商品详情',
                            close: true,
                            url: 'psi/inventoryGoodsDetail.html' + condition
                        });
                    }
                    if (pageType == 'edit' ) {
                        condition += '&pageType=edit'+ "&isAdd=0";
                        top.addTabs({
                            id: 'GoodsDetail',
                            title: '商品详情',
                            close: true,
                            url: 'psi/inventoryGoodsDetail.html' + condition + "&t=" + new Date()
                        });
                    }
                }
                else {
                    var condition = '?id=' + purchaseId;
                    if (pageType != 'edit') {
                        $.dialog({
                            content: 'url:/page/psi/purchase.html'+ condition + '&pageType=' + pageType +'&type=' + type ,
                            title: '申购物品详情',
                            width: 904,
                            height: 665,
                            max: true,
                            min: true,
                            lock: true
                        });
                    }
                    if (pageType == 'edit' ) {
                        $.dialog({
                            content: 'url:/page/psi/purchase.html'+ condition + '&pageType=' +pageType + '&type=' + type + "&t="+ new Date(),
                            title: '申购物品详情',
                            width: 904,
                            height: 665,
                            max: true,
                            min: true,
                            lock: true
                        });
                    }
                }
            },
            //查询方法
            search: function () {
                $.wyui.page.queryParams.requestPage = 1;
                $.extend($.wyui.page.queryParams, this.searchParams);
                this.getGoodsList()
            },
            convertAuditFlagToName: function (item) {
                switch (Number(item.auditFlag)) {
                    case -1:
                        return "-";
                        break;
                    case 0:
                        return "待-"+item.currentAuditorName+"-审核";
                        break;
                    case 1:
                        return "已通过";
                        break;
                    case 2:
                        return "已驳回";
                        break;
                    default :
                        break;
                }
            },
            convertStateToName: function (item) {
                switch (Number(item.state)) {
                    case -1:
                        return "申购中";
                        break;
                    case 0:
                        return "待采购";
                        break;
                    case 1:
                        return "采购在途";
                        break;
                    case 2:
                        return "待入库";
                        break;
                    case 3:
                        return "入库完成";
                        break;
                    default :
                        break;
                }
            },
            isArray: function (id) {
                var that = this;
                if ($.inArray(id, that.selectIds) > -1) {
                    // 如果已经包含了该id, 则去除(单选按钮由选中变为非选中状态)
                    return true;
                } else {
                    // 选中该checkbox
                    return false;
                }
            },
            isEnable: function (item) {
                return true;
            },
            checked: function (item) {
                var that = this;
                if (item.purchaseId==that.selectId) {
                    // 如果已经包含了该id, 则去除(单选按钮由选中变为非选中状态)
                    that.selectId='';
                } else {
                    // 选中该checkbox
                    that.selectId=item.purchaseId;
                }
            },
        },
        mounted: function () {
            var that = this;
            console.log(JSON.stringify(currentUser))
        }
    });
    function selectAll() {
        var isCheck = $("#sel_1").is(':checked');  //获得全选复选框是否选中
        $("input[type='checkbox']").each(function () {
            this.checked = isCheck;       //循环赋值给每个复选框是否选中
        });
    };
    $.wyui.page.dataUrl = server.ip + urlConfig.psi.purchase.getPurchaseList;
    $.wyui.page.queryParams.pageType = $.wyui.page.urlParams.pageType;
    $.extend($.wyui.page.queryParams, app.searchParams);
    $.wyui.page.getByPage_callback = function (records) {
        var data=records;
        for(var i=0;i<data.length;i++){
            var goodsName=[];
            for(var b=0;b<data[i].goodsInfo.length;b++) {
                var data2=data[i].goodsInfo[b]
                goodsName.push(data2.goodsName+"*"+data2.count)
            }
            data[i].goodsName=goodsName.join(",")
        }
        console.log(data)
        app.list = data;
        document.getElementById("scrollDiv").scrollTop = 0;
    };
    $.wyui.page.getByPage_scroll_callback = function (list) {
        if (list.length < 30) {
            isLoad = false;
        } else {
            for (var i = 0; i < list.length; i++) {
                app.list.push(list[i]);
            }
            isLoad = true;
        }
    };
</script>
<script>
    /************************滚动加载******************************/
    var divscroll = document.getElementById('scrollDiv');

    function divScroll() {
        var wholeHeight = divscroll.scrollHeight;
        var scrollTop = divscroll.scrollTop;
        var divHeight = divscroll.clientHeight;
        console.log(scrollTop + divHeight, wholeHeight)
        if (scrollTop + divHeight >= wholeHeight - 2) {
//            alert('滚动到底部了！');
            if (isLoad) {
                isLoad = false;
                setTimeout($.wyui.page.getByPage("scroll"), 1000);

            }

            //这里写动态加载的逻辑，比如Ajax请求后端返回下一个页面的内容
        }

    }

    divscroll.onscroll = divScroll;
</script>
</body>
</html>